from observable import Observable

class AlbumData(object):
   db = []
   def __init__(self, artist, album, classical, composer):
      if album in AlbumData.db:
         album = str(id(self))
      AlbumData.db.append(album)
      self.artist = artist
      self.album = album
      self.classical = classical
      self.composer = composer
   def __repr__(self):
      return 'artist=%s album=%s classical=%s composer=%s' % (self.artist, self.album, self.classical, self.composer)
      
class AlbumModel(object):
   def __init__(self):
      self.count = Observable()
      self.index = Observable()
      self.list = Observable()
      self.artist = Observable()
      self.album= Observable()
      self.classical = Observable()
      self.composer = Observable()
   def start(self):
      self.list.value = [] # read from db
      self.maintain()
   def maintain(self):
      print 'maintain'
      self.list.value = AlbumData.db
      self.count.value = len(self.list.value)
      self.index.value = self.count.value - 1
   def append(self, artist, album, classical, composer):
      AlbumData(artist, album, classical, composer)
      self.maintain()
